package manage.manager;

import core.redis.RedisService;
import manage.domain.exam.Exam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import core.constants.Constant;

@Component
public class ExamCacheManage {
    @Autowired
    private RedisService redisService;

    public void addCache(Exam exam){
        redisService.leftPushForList(getIngExamKey(), exam.getExamId());
        redisService.setCacheObject(getDetailKey(exam.getExamId()), exam);
    }

    public void deleteCache(Exam exam) {
        redisService.removeForList(getIngExamKey(), exam.getExamId());
        redisService.deleteObject(getDetailKey(exam.getExamId()));
        redisService.deleteObject(Constant.EXAM_QUESTION_LIST + exam.getExamId());

    }
    public String getIngExamKey(){
        return Constant.ING_EXAM_LIST_KEY;
    }

    public String getDetailKey(Long examId){
        return Constant.EXAM_DETAIL_KEY + examId;
    }
    public String getEdExamKey(){
        return Constant.ED_EXAM_LIST_KEY;
    }


}
